home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / createRenderNode.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  34.5 KB  |  1,294 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File MODIFY THIS AT YOUR OWN RISK
  19. //
  20. //  Creation Date:  20 August 1996
  21. //  Author:         sw, cdt
  22. //
  23. //  Procedure Name:
  24. //      createRenderNode
  25. //
  26. //  Description:
  27. //        Procedure to popup the render creation window.
  28. //
  29. //  Input Arguments:
  30. //        A flag specifying which types of render nodes to create.
  31. //        Currently "-all", "-allWithTexturesUp", "-allWithShadersUp", 
  32. //        "-allWithLightsUp", "-textures", "-shadersSG", "-shaders", 
  33. //        "-lights", "-utilities" are supported.
  34. //
  35. //      The command to run after the a node has been created. The name
  36. //      of the created node will substituted "%node" in the command
  37. //      string. If an empty string is passed for the command nothing
  38. //      will be done. Currently the command is only attached to the
  39. //      buttons in the texture tab.
  40. //
  41. //        If a command is specified the createRenderNode window will be
  42. //        closed.
  43. //
  44. //  Return Value:
  45. //      None.
  46. //
  47. //////////////////////////////////////////////////////////////////////
  48. //
  49. //  Procedure Name:
  50. //      createRenderNodeCB
  51. //
  52. //  Description:
  53. //        Procedure to create the node classified as specifed by the inputs
  54. //
  55. //  Input Arguments:
  56. //        $as - 
  57. //        A flag specifying which how to classify the node created.
  58. //        Choices:
  59. //            -as2DTexture : 2d textures
  60. //            -as3DTexture : 3d textures
  61. //            -asEnvTexture : Environment textures
  62. //            -asShader : as a shader
  63. //            -asLight : as a light
  64. //            -asUtility : as a rendering utility node
  65. //
  66. //      $flag - 
  67. //            A secondary flag used to make decisions in combination with $as.
  68. //            Choices:
  69. //                -asBump : defines a created texture as a bump
  70. //                -asNoShadingGroup : for materials; create without a shading group
  71. //                -asDisplacement : for anything; map the created node 
  72. //                    to a displacement material.
  73. //                -asUtility : for anything; do whatever the $as flag says,
  74. //                    but also classify as a utility
  75. //                -asPostProcess : for any postprocess node
  76. //
  77. //        $type - 
  78. //            The type of node to be created.
  79. //
  80. //        $command - 
  81. //            A command entered by the user when invoking createRenderNode.
  82. //        The command will substitute the string %node with the name of the
  83. //        node it creates.  createRenderWindow will be closed if a command
  84. //        is not the null string ("").
  85. //
  86. //  Return Value:
  87. //      None.
  88. //
  89.  
  90. global proc string createRenderNodeCB ( string $as, string $flag,
  91.                                  string $type, string $postCommand )
  92. {
  93.     int $projection = (`optionVar -query create2dTextureType` == "projection");
  94.     int $stencil = (`optionVar -query create2dTextureType` == "stencil");
  95.     int $placement = `optionVar -query createTexturesWithPlacement`;
  96.     int $shadingGroup = `optionVar -query createMaterialsWithShadingGroup`;
  97.     int $createAndDrop = 0;
  98.     string $editor = "";
  99.  
  100.     return renderCreateNode(
  101.         $as,
  102.         $flag,
  103.         $type, 
  104.         $postCommand,
  105.         $projection,
  106.         $stencil,
  107.         $placement,
  108.         $shadingGroup,
  109.         $createAndDrop,
  110.         $editor);
  111. }
  112.  
  113. proc string smallUIName (string $nodeName)
  114. {
  115.     // In most cases we can just take the given name and
  116.     // add spaces to make it more appealing.  For a few
  117.     // larger names we will override the name with a
  118.     // shorter version.  This makes the whole window smaller.
  119.     //
  120.     string $labelName;
  121.  
  122.     switch ($nodeName) {
  123.         case "displacementShader":
  124.             $labelName = "Displacement";
  125.             break;
  126.         case "plusMinusAverage":
  127.             $labelName = "+/- Average";
  128.             break;
  129.         case "doubleShadingSwitch":
  130.             $labelName = "Double Switch";
  131.             break;
  132.         case "quadShadingSwitch":
  133.             $labelName = "Quad Switch";
  134.             break;
  135.         case "singleShadingSwitch":
  136.             $labelName = "Single Switch";
  137.             break;
  138.         case "tripleShadingSwitch":
  139.             $labelName = "Triple Switch";
  140.             break;
  141.         case "particleSamplerInfo":
  142.             $labelName = "Particle Sampler";
  143.             break;
  144.         case "surfaceLuminance":
  145.             $labelName = "Surf. Luminance";
  146.             break;
  147.         case "place2dTexture":
  148.             $labelName = "2d Placement";
  149.             break;
  150.         case "place3dTexture":
  151.             $labelName = "3d Placement";
  152.             break;
  153.         default:
  154.             $labelName = interToUI($nodeName);
  155.             break;
  156.     }    
  157.     
  158.      return $labelName;
  159. }
  160.  
  161. global proc refreshButtons( string $classification, string $RClayout )
  162. {
  163.  
  164.     int $buttonHeight = 34;  // default for Icons and Text
  165.     int $columnWidth = 135;  // default for Icons and Text
  166.  
  167.     if (`about -os` == "nt")
  168.     {
  169.         $columnWidth = 145;  // a bit wider on NT than on IRIX
  170.     }
  171.  
  172.     string $buttonStyle = `optionVar -query createRenderNodeButtonStyle`;
  173.     int $iconsOnly = ($buttonStyle == "Icons Only");
  174.     int $textOnly = ($buttonStyle == "Text Only");
  175.  
  176.     if ($textOnly) {
  177.         $buttonHeight = 24;
  178.         $columnWidth = 120;
  179.     } 
  180.  
  181.     int $dynamicsIsLicensed = `licenseCheck -mode edit -type fx`;
  182.  
  183.     if (!$iconsOnly) {
  184.         rowColumnLayout -numberOfColumns 2 
  185.             -rowAttach 1 "top" 4 -rowAttach 2 "top" 4
  186.             -columnAttach 1 "both" 2 -columnAttach 2 "both" 2
  187.             -columnWidth 1 $columnWidth -columnWidth 2 $columnWidth 
  188.             $RClayout;
  189.     } else {
  190.         rowColumnLayout -numberOfColumns 6 
  191.             -rowAttach 1 "top" 0 -rowAttach 2 "top" 0
  192.             -columnAttach 1 "both" 0 -columnAttach 2 "both" 0
  193.             -columnAttach 3 "both" 0 -columnAttach 4 "both" 0
  194.             -columnAttach 5 "both" 0 -columnAttach 6 "both" 0
  195.             -columnWidth 1 40 -columnWidth 2 40  
  196.             -columnWidth 3 40 -columnWidth 4 40  
  197.             -columnWidth 5 40 -columnWidth 6 40  
  198.             $RClayout;
  199.     }
  200.  
  201.     string $nodes[] = `listNodeTypes $classification`;
  202.     for( $name in $nodes ) {
  203.         string $labelName = smallUIName($name);
  204.  
  205.         // Add a frame layout here to make the nodeIconButton appear raised
  206.         // like a normal button.
  207.         //
  208.         frameLayout
  209.             -labelVisible false
  210.             -borderStyle "out"
  211.             -collapsable false;
  212.  
  213.             // Create the button
  214.             //
  215.             nodeIconButton 
  216.                 -height $buttonHeight
  217.                 ($name+"Btn");
  218.  
  219.         setParent ..; // from frame layout
  220.  
  221.         if ( $iconsOnly ) 
  222.         {
  223.             // Add an image and annotation to the button
  224.             //
  225.             nodeIconButton 
  226.                 -edit
  227.                 -image1 ("render_" + $name + ".xpm")
  228.                 -annotation $labelName 
  229.                 ($name+"Btn");
  230.         } 
  231.         else if ( $textOnly ) 
  232.         {
  233.             // Add a label to the button
  234.             //
  235.             if(`about -mac`){
  236.                 nodeIconButton 
  237.                     -edit
  238.                     -style "textOnly"
  239.                     -label (" " + $labelName) 
  240.                     -annotation $labelName 
  241.                     ($name+"Btn");
  242.             }else{
  243.                 nodeIconButton 
  244.                     -edit
  245.                     -style "iconAndTextHorizontal"
  246.                     -label (" " + $labelName) 
  247.                     -annotation $labelName 
  248.                     ($name+"Btn");
  249.             }
  250.         } 
  251.         else 
  252.         {  // icons and Text
  253.             // Add an image and a label to the button
  254.             //
  255.             nodeIconButton 
  256.                 -edit
  257.                 -image1 ("render_" + $name + ".xpm")
  258.                 -style "iconAndTextHorizontal"
  259.                 -label (" " + $labelName) 
  260.                 -annotation $labelName 
  261.                 ($name+"Btn");
  262.         }
  263.  
  264.         if( !$dynamicsIsLicensed && 
  265.             ( $name == "particleCloud" ||
  266.               $classification == "utility/particle" ) ) 
  267.         {
  268.             // The user does not have a license which allows them to create
  269.             // this node type, so we will disable the button.
  270.             //
  271.             nodeIconButton 
  272.                 -edit
  273.                 -enable false 
  274.                 ($name+"Btn");
  275.         }
  276.     }
  277.  
  278.     setParent ..;
  279. }
  280.  
  281. proc setupButtons( string $classification,
  282.                    string $as,
  283.                    string $flag,
  284.                    string $postCommand )
  285. {
  286.     string $command;
  287.  
  288.     string $nodes[] = `listNodeTypes $classification`;
  289.  
  290.     for( $name in $nodes ) {
  291.         if( `nodeIconButton -exists ($name+"Btn")` ) {
  292.             $command = "createRenderNodeCB " +
  293.                 $as + " " +
  294.                 "\"" + $flag + "\" " +
  295.                 $name + " " +
  296.                 "\"" + $postCommand + "\"";
  297.  
  298.             nodeIconButton -e -command $command ($name+"Btn");
  299.         }
  300.     }
  301. }
  302.  
  303. proc buildTextures ()
  304. //
  305. //    Building the textures tab.
  306. //
  307. {
  308.     columnLayout -adj true texturesTab;
  309.  
  310.         separator -style "none" -height 5;
  311.  
  312.         checkBox 
  313.             -label "With New Texture Placement" 
  314.             -align left
  315.             -value `optionVar -query createTexturesWithPlacement` 
  316.             -onCommand 
  317.                 ("optionVar -intValue createTexturesWithPlacement true;"
  318.                     + "refreshCreateNodeUI;")
  319.             -offCommand 
  320.                 ("optionVar -intValue createTexturesWithPlacement false;"
  321.                     + "refreshCreateNodeUI;")
  322.             placementCheckBox;
  323.  
  324.         separator -style "none" -height 5;
  325.  
  326.         //
  327.         //    Building subtab for all 2d Textures
  328.         //
  329.  
  330.         frameLayout -l "2D Textures" 
  331.             -borderVisible true -collapsable true 
  332.             -borderStyle "etchedIn"
  333.             -marginWidth 5
  334.             -marginHeight 5
  335.             -collapse false twoDTexturesF;
  336.  
  337.             columnLayout twoDTexturesC;
  338.  
  339.                  radioCollection radioOptions;
  340.                  radioButton 
  341.                     -label "Normal" 
  342.                     -onCommand 
  343.                         ("optionVar "
  344.                             + "-stringValue create2dTextureType \"normal\";"
  345.                             + "refreshCreateNodeUI();")
  346.                     normalRadioBtn;
  347.                  radioButton 
  348.                     -label "As projection" 
  349.                     -onCommand 
  350.                         ("optionVar "
  351.                             + "-stringValue create2dTextureType \"projection\";"
  352.                             + "refreshCreateNodeUI();")
  353.                     projectionRadioBtn;
  354.                 radioButton 
  355.                     -label "As stencil" 
  356.                     -onCommand 
  357.                         ("optionVar "
  358.                             + "-stringValue create2dTextureType \"stencil\";"
  359.                             + "refreshCreateNodeUI();")
  360.                     stencilRadioBtn;
  361.                 
  362.                 if (`optionVar -query create2dTextureType` == "normal")
  363.                 {
  364.                     radioButton 
  365.                         -edit
  366.                         -select
  367.                         normalRadioBtn;
  368.                 }
  369.                 else if (`optionVar -query create2dTextureType` == "projection")
  370.                 {
  371.                     radioButton 
  372.                         -edit
  373.                         -select
  374.                         projectionRadioBtn;
  375.                 }
  376.                 else // (`optionVar -query create2dTextureType` == "stencil")
  377.                 {
  378.                     radioButton 
  379.                         -edit
  380.                         -select
  381.                         stencilRadioBtn;
  382.                 }
  383.  
  384.                 separator -style "none" -height 5;
  385.  
  386.                 refreshButtons("texture/2d","twoDTexturesRC");
  387.  
  388.             setParent ..;
  389.  
  390.         setParent ..;
  391.  
  392.         //
  393.         //    Building subtab for all 3D Textures
  394.         //
  395.  
  396.         frameLayout -l "3D Textures" -borderVisible true -collapsable true 
  397.             -borderStyle "etchedIn"
  398.             -marginWidth 5
  399.             -marginHeight 5
  400.             -collapse false threeDTexturesF;
  401.  
  402.             columnLayout threeDTexturesC;
  403.  
  404.                 refreshButtons("texture/3d","threeDTexturesRC");
  405.  
  406.             setParent ..;
  407.  
  408.         setParent ..;
  409.  
  410.  
  411.         //
  412.         //  Building subtab for all Env Textures
  413.         //
  414.  
  415.         frameLayout -l "Environment Textures" -borderVisible true 
  416.             -borderStyle "etchedIn"
  417.             -marginWidth 5
  418.             -marginHeight 5
  419.             -collapsable true 
  420.             -collapse true envTexturesF;
  421.  
  422.             columnLayout envTexturesC;
  423.  
  424.                 refreshButtons("texture/environment","envTexturesRC");
  425.  
  426.             setParent ..;
  427.         
  428.         setParent ..;
  429.  
  430.         //
  431.         //    Building subtab for all other Textures
  432.         //
  433.  
  434.         frameLayout -l "Other Textures" 
  435.             -borderVisible true -collapsable true 
  436.             -borderStyle "etchedIn"
  437.             -marginWidth 5
  438.             -marginHeight 5
  439.             -collapse false otherTexturesF;
  440.  
  441.             columnLayout otherTexturesC;
  442.  
  443.                     refreshButtons("texture/other","otherTexturesRC");
  444.  
  445.             setParent ..;
  446.  
  447.         setParent ..;
  448.  
  449.  
  450.     setParent ..;                // columnLayout texturesTab
  451. }
  452.  
  453. proc setupTextures ( string $postCommand, string $flag )
  454. {
  455.     setParent texturesTab;
  456.  
  457.     setupButtons("texture/2d", "-as2DTexture", $flag, $postCommand);
  458.     setupButtons("texture/3d", "-as3DTexture", $flag, $postCommand);
  459.     setupButtons("texture/environment", "-asEnvTexture", $flag, $postCommand);
  460.     setupButtons("texture/other", "-asTexture", $flag, $postCommand);
  461. }
  462.  
  463. proc buildShaders ()
  464. //
  465. //    Building the shaders tab.
  466. //
  467. {
  468.     columnLayout -adj true shadersTab;
  469.  
  470.         separator -style "none" -height 5;
  471.  
  472.         checkBox 
  473.             -label "With Shading Group" 
  474.             -align left
  475.             -value `optionVar -query createMaterialsWithShadingGroup`
  476.             -onCommand 
  477.                 ("optionVar -intValue createMaterialsWithShadingGroup true;"
  478.                     + "refreshCreateNodeUI;")
  479.             -offCommand 
  480.                 ("optionVar -intValue createMaterialsWithShadingGroup false;"
  481.                     + "refreshCreateNodeUI;")
  482.             shadingGroupCheckBox;
  483.  
  484.         separator -style "none" -height 5;
  485.  
  486.         frameLayout -l "Surface Materials" -borderVisible true -collapsable true 
  487.             -borderStyle "etchedIn"
  488.             -marginWidth 5
  489.             -marginHeight 5
  490.             -collapse false
  491.             surfShadersF;
  492.  
  493.             columnLayout surfShadersC;
  494.  
  495.                 refreshButtons("shader/surface","surfShadersRC");
  496.  
  497.             setParent ..;        
  498.  
  499.            setParent ..;
  500.  
  501.  
  502.         //
  503.         //  Building subtab for all  Fog Shaders
  504.         //
  505.  
  506.         frameLayout -l "Volumetric Materials" -borderVisible true -collapsable true 
  507.             -borderStyle "etchedIn"
  508.             -marginWidth 5
  509.             -marginHeight 5
  510.             -collapse true fogShadersF;
  511.  
  512.             columnLayout fogShadersC;
  513.  
  514.                 refreshButtons("shader/volume","fogShadersRC");
  515.  
  516.             setParent ..;
  517.  
  518.            setParent ..;
  519.  
  520.         //
  521.         //  Building subtab for all Displacement Shaders
  522.         //
  523.  
  524.         frameLayout -l "Displacement Materials" -borderVisible true -collapsable true 
  525.             -borderStyle "etchedIn"
  526.             -marginWidth 5
  527.             -marginHeight 5
  528.             -collapse true displacementShadersF;
  529.  
  530.             columnLayout displacementShadersC;
  531.  
  532.                 refreshButtons("shader/displacement","displacementShadersRC");
  533.  
  534.             setParent ..;
  535.  
  536.            setParent ..;
  537.  
  538.     setParent ..;
  539.  
  540. }
  541.  
  542. proc setupShaders ( string $postCommand, string $flag )
  543. {
  544.     setParent shadersTab;
  545.  
  546.     string $command;
  547.  
  548.     if ($flag != "") {
  549.         setupButtons("shader", "-asShader", $flag, $postCommand);
  550.     }
  551.     else {
  552.         setupButtons("shader/surface", "-asShader", "surfaceShader", $postCommand);
  553.         setupButtons("shader/volume", "-asShader", "volumeShader", $postCommand);
  554.         setupButtons("shader/displacement", "-asShader", "displacementShader", $postCommand);
  555.     }
  556. }
  557.  
  558. proc buildLights ()
  559. //
  560. //    Building the lights tab.
  561. //
  562. {
  563.     columnLayout -adj true lightsTab;
  564.  
  565.         frameLayout -l "Lights" -borderVisible true -collapsable true 
  566.             -borderStyle "etchedIn"
  567.             -marginWidth 5
  568.             -marginHeight 5
  569.             -collapse false
  570.             lightsF;
  571.  
  572.             columnLayout lightsC;
  573.  
  574.                 refreshButtons("light","lightsRC");
  575.  
  576.             setParent ..;
  577.  
  578.         setParent ..;
  579.  
  580.     setParent ..;
  581. }
  582.  
  583. proc setupLights ( string $postCommand, string $flag )
  584. {
  585.     setParent lightsTab;
  586.  
  587.     setupButtons("light", "-asLight", $flag, $postCommand);
  588. }
  589.  
  590. proc buildUtilities ()
  591. //
  592. //  Building the utilities tab.
  593. //
  594. {
  595.     columnLayout -adj true utilitiesTab;
  596.         //
  597.         //    Building subtab for general utilities
  598.         //
  599.         frameLayout -l "General Utilities" -borderVisible true -collapsable true 
  600.             -borderStyle "etchedIn"
  601.             -marginWidth 5
  602.             -marginHeight 5
  603.             -collapse false    generalUtilsF;    
  604.  
  605.             columnLayout generalUtilsC;
  606.  
  607.                 refreshButtons("utility/general","generalUtilsRC");
  608.  
  609.             setParent ..;
  610.  
  611.         setParent ..;
  612.  
  613.  
  614.         //
  615.         //    Building subtab for color utilities
  616.         //
  617.         frameLayout -l "Color Utilities" -borderVisible true -collapsable true 
  618.             -borderStyle "etchedIn"
  619.             -marginWidth 5
  620.             -marginHeight 5
  621.             -collapse false    colorUtilsF;    
  622.     
  623.             columnLayout colorUtilsC;
  624.     
  625.                 refreshButtons("utility/color","colorUtilsRC");
  626.  
  627.             setParent ..;
  628.  
  629.         setParent ..;
  630.  
  631.         //
  632.         //    Building subtab for switch utilities
  633.         //
  634.         frameLayout -l "Switch Utilities" -borderVisible true -collapsable true 
  635.             -borderStyle "etchedIn"
  636.             -marginWidth 5
  637.             -marginHeight 5
  638.             -collapse true switchUtilsF;    
  639.  
  640.             columnLayout switchUtilsC;
  641.  
  642.                 refreshButtons("utility/switch","switchUtilsRC");
  643.  
  644.             setParent ..;
  645.  
  646.         setParent ..;
  647.  
  648.         //
  649.         //  Building subtab for particle utilities
  650.         //
  651.         frameLayout -l "Particle Utilities" -borderVisible true -collapsable true
  652.             -borderStyle "etchedIn"
  653.             -marginWidth 5
  654.             -marginHeight 5
  655.             -collapse true partUtilsF;
  656.  
  657.             columnLayout partUtilsC;
  658.  
  659.                 refreshButtons("utility/particle","partUtilsRC");
  660.  
  661.             setParent ..;
  662.  
  663.         setParent ..;
  664.  
  665.         if (`licenseCheck -m "edit" -typ "complete"`) {
  666.             //
  667.             //  Building subtab for image planes
  668.             //
  669.             frameLayout -l "Image Planes" -borderVisible true -collapsable true
  670.                 -borderStyle "etchedIn"
  671.                 -marginWidth 5
  672.                 -marginHeight 5
  673.                 -collapse true imgUtilsF;
  674.     
  675.                 columnLayout imgUtilsC;
  676.     
  677.                     refreshButtons("imageplane","imgUtilsRC");
  678.     
  679.                 setParent ..;
  680.     
  681.             setParent ..;
  682.         }
  683.  
  684.         //
  685.         //  Building subtab for glow
  686.         //
  687.         frameLayout -l "Glow" -borderVisible true -collapsable true
  688.             -borderStyle "etchedIn"
  689.             -marginWidth 5
  690.             -marginHeight 5
  691.             -collapse true glowUtilsF;
  692.  
  693.             columnLayout glowUtilsC;
  694.  
  695.                 refreshButtons("postprocess/opticalFX","glowUtilsRC");
  696.  
  697.             setParent ..;
  698.  
  699.         setParent ..;
  700.  
  701.     setParent ..;
  702. }
  703.  
  704. proc setupUtilities ( string $postCommand, string $flag )
  705. {
  706.     setParent utilitiesTab;
  707.  
  708.     setupButtons("utility/general", "-asUtility", $flag, $postCommand);
  709.     setupButtons("utility/switch", "-asUtility", $flag, $postCommand);
  710.     setupButtons("utility/color", "-asUtility", $flag, $postCommand);
  711.     setupButtons("utility/particle", "-asUtility", $flag, $postCommand);
  712.  
  713.     if (`licenseCheck -m "edit" -typ "complete"`) {
  714.         setupButtons("imageplane", "-asUtility", $flag, $postCommand);
  715.     }
  716.  
  717.     setupButtons("postprocess/opticalFX", "-asPostProcess", $flag, $postCommand);
  718. }
  719.  
  720. global proc setCreateRenderNodeButtonStyle()
  721. //
  722. //    sets the createRenderNodeButton OptionVar for button styles in
  723. //    the createRenderNodeWindow
  724. //
  725. {
  726.     int $iconsAndText = `menuItem -q -radioButton iconsAndTextItem`;
  727.     int $iconsOnly = `menuItem -q -radioButton iconsOnlyItem`;
  728.     int $textOnly = `menuItem -q -radioButton textOnlyItem`;
  729.  
  730.     if ( $iconsAndText) 
  731.     {   
  732.         optionVar -stringValue "createRenderNodeButtonStyle" "Icons and Text";
  733.     } 
  734.     else if ( $iconsOnly ) 
  735.     { 
  736.         optionVar -stringValue "createRenderNodeButtonStyle" "Icons Only";
  737.     } 
  738.     else if ( $textOnly ) 
  739.     {
  740.         optionVar -stringValue "createRenderNodeButtonStyle" "Text Only";
  741.     }
  742.  
  743. }
  744.  
  745. global proc toggleCreateRenderNodeWindowStyle ()
  746. //
  747. //  toggles the style and requests a redraw of the buttons in 
  748. //  the createRenderNodeWindow 
  749. //
  750. {
  751.     string $class = "texture/2d:texture/3d:texture/environment:texture/other:shader/surface:" +
  752.                     "shader/volume:shader/displacement:light:utility/general:utility/switch:" +
  753.                     "utility/color:utility/particle:imageplane:postprocess/opticalFX";
  754.  
  755.     setCreateRenderNodeButtonStyle;
  756.        refreshCreateRenderNodeWindow($class);
  757.  
  758. }
  759.  
  760. global int $gCreateRenderNodePluginCallbacksRegistered = false;
  761.  
  762. global proc createRenderNode( 
  763.     string $nodeTypesFlag, 
  764.     string $command, 
  765.     string $flag )
  766. //
  767. //    the creationWindow is the window which gives the user the 
  768. //     ability to choose from different texture types
  769. //
  770. {
  771.     int $showMentalRayCustomShaders = 0;
  772.     int $mentalRayPluginLoaded = 0;
  773.  
  774.     if (`getenv MAYA_MRFM_SHOW_CUSTOM_SHADERS` == "1")
  775.     {
  776.         $showMentalRayCustomShaders = 1;
  777.     }
  778.  
  779.     if (`pluginInfo -query -loaded Mayatomr`)
  780.     {
  781.         $mentalRayPluginLoaded = 1;
  782.     }
  783.  
  784.     int $crnWindowWidth = 315; 
  785.  
  786.     // Initialize the optionVar which specifies what style the buttons in the
  787.     // create render node dialog should be drawn in, if the optionVar doesn't
  788.     // already exist.
  789.     //
  790.     if (!`optionVar -exists createRenderNodeButtonStyle`)
  791.     {
  792.         optionVar -stringValue createRenderNodeButtonStyle "Icons and Text";
  793.     }
  794.  
  795.     string $buttonStyle = `optionVar -q createRenderNodeButtonStyle`;
  796.     int $textOnly = ($buttonStyle == "Text Only");
  797.  
  798.     if ($textOnly) {
  799.         $crnWindowWidth = 300;
  800.     }
  801.  
  802.     if (!`window -exists createRenderNodeWindow`) {
  803.         window -rtf false
  804.             -title "Create Render Node"
  805.             -iconName "Create Render Node"
  806.             -menuBar true
  807.             -maximizeButton false
  808.             -ret 
  809.             -wh $crnWindowWidth 730 
  810.             createRenderNodeWindow;
  811.  
  812.         //
  813.         // Setup up the menu bar
  814.         //
  815.  
  816.         menu -label "Options" optionsMenu;
  817.             
  818.             radioMenuItemCollection;
  819.  
  820.             menuItem -l "Icons Only"
  821.                 -radioButton off 
  822.                 -command "toggleCreateRenderNodeWindowStyle"
  823.                 iconsOnlyItem;
  824.             menuItem -l "Icons and Text"
  825.                 -radioButton off 
  826.                 -command "toggleCreateRenderNodeWindowStyle"
  827.                 iconsAndTextItem;
  828.             menuItem -l "Text Only"
  829.                 -radioButton off 
  830.                 -command "toggleCreateRenderNodeWindowStyle"
  831.                 textOnlyItem;
  832.         
  833.         setParent -m ..;  // from optionsMenu
  834.  
  835.         menu -label "Help" -helpMenu true;
  836.  
  837.             menuItem -label "Help on Create Render Node..."
  838.                 -enableCommandRepeat false
  839.                 -command "showHelp CreateRenderNode";
  840.         
  841.         setParent -m ..;
  842.  
  843.         //
  844.         // setup initial values of the menuItems on the Options menu
  845.         //
  846.  
  847.         string $crnButtonStyle = `optionVar -q createRenderNodeButtonStyle`;
  848.  
  849.         if ( $crnButtonStyle == "Icons and Text") 
  850.         {
  851.             // set to icons and text
  852.             menuItem -e -radioButton on iconsAndTextItem;
  853.         } 
  854.         else if ( $crnButtonStyle == "Icons Only") 
  855.         {
  856.             // set to icons only 
  857.             menuItem -e -radioButton on iconsOnlyItem;
  858.         } 
  859.         else if ( $crnButtonStyle == "Text Only") 
  860.         {
  861.             // set to text only
  862.             menuItem -e -radioButton on textOnlyItem;
  863.         } 
  864.         else 
  865.         {   
  866.             // set to icons and text by default
  867.             menuItem -e -radioButton on iconsAndTextItem;
  868.         }
  869.  
  870.         //
  871.         // Create a variable to hold the current location of the
  872.         // $parent and ask the current location to be assigned to the
  873.         // variable.  This variable is passed onto other function to
  874.         // ensure widgets to have the correct $parent.
  875.         //
  876.  
  877.         string $parent = `setParent -query`;
  878.  
  879.         formLayout creationWindowForm;
  880.  
  881.             tabLayout -tv false indexTab;
  882.                 tabLayout -scr true -horizontalScrollBarThickness 0 creationWindowTabs;
  883.                     buildShaders;
  884.                     buildTextures;
  885.                     buildLights;
  886.                     buildUtilities;
  887.  
  888.                     if ($showMentalRayCustomShaders && $mentalRayPluginLoaded)
  889.                     {
  890.                         mrCreateNodeWindow_BuildTab;
  891.                     }
  892.  
  893.                 setParent ..;
  894.             setParent ..;
  895.  
  896.             tabLayout -e 
  897.                 -tl shadersTab "Materials"
  898.                 -tl texturesTab "Textures"
  899.                 -tl lightsTab "Lights"
  900.                 -tl utilitiesTab "Utilities"
  901.                 creationWindowTabs;
  902.  
  903.             if ($showMentalRayCustomShaders && $mentalRayPluginLoaded)
  904.             {
  905.                 tabLayout -e 
  906.                     -tl mentalRayTab "mental ray"
  907.                     creationWindowTabs;
  908.             }
  909.  
  910.             button -l "Close" 
  911.                 -h 26
  912.                 -c "window -e -vis false createRenderNodeWindow" 
  913.                 closeButton;
  914.         setParent ..;
  915.  
  916.         formLayout -e
  917.             -af indexTab "left" 1
  918.             -af indexTab "right" 1
  919.             -af indexTab "top" 1
  920.             -ac indexTab "bottom" 5 closeButton
  921.  
  922.             -af closeButton "left" 5
  923.             -af closeButton "right" 5
  924.             -af closeButton "bottom" 5
  925.             -an closeButton "top"
  926.             creationWindowForm;
  927.     }
  928.     
  929.     //  If the window already existed, but the mental ray tab 
  930.     //  did not, then we want to create the mental ray tab (assuming custom 
  931.     //  shaders are to be shown). This ensures that the mental ray tab gets 
  932.     //  created if the mental ray plugin is loaded dynamically.
  933.     //
  934.     else if (!`columnLayout -exists mentalRayTab` && 
  935.         $showMentalRayCustomShaders && $mentalRayPluginLoaded)
  936.     {
  937.         setParent creationWindowTabs;
  938.         mrCreateNodeWindow_BuildTab;
  939.         tabLayout -edit
  940.             -tl mentalRayTab "mental ray"
  941.             creationWindowTabs;
  942.     }
  943.  
  944.     setParent createRenderNodeWindow;
  945.  
  946.     string $first4 = substring($nodeTypesFlag,1,4);
  947.  
  948.     if ($first4 == "-all") {
  949.         setupShaders $command $flag;
  950.         setupTextures $command $flag;
  951.         setupLights $command $flag;
  952.         setupUtilities $command $flag;
  953.         if ($showMentalRayCustomShaders && $mentalRayPluginLoaded) {
  954.             mrCreateNodeWindow_SetupTab $command $flag;
  955.         }
  956.  
  957.         tabLayout -e -tv false indexTab;
  958.         if($nodeTypesFlag != "-all") {
  959.             if($nodeTypesFlag == "-allWithShadersUp") {
  960.                 tabLayout -e -tv true -selectTabIndex 1 creationWindowTabs;
  961.             } else if($nodeTypesFlag == "-allWithTexturesUp") {
  962.                 tabLayout -e -tv true -selectTabIndex 2 creationWindowTabs;
  963.             } else if($nodeTypesFlag == "-allWithLightsUp") {
  964.                 tabLayout -e -tv true -selectTabIndex 3 creationWindowTabs;
  965.             } else if($nodeTypesFlag == "-allWithMentalUp") {
  966.                 if ($showMentalRayCustomShaders && $mentalRayPluginLoaded) {
  967.                     tabLayout -e -tv true -selectTabIndex 5 creationWindowTabs;
  968.                 }
  969.             }
  970.         } else {
  971.             tabLayout -e -tv true creationWindowTabs;
  972.         }
  973.     }
  974.     else if ($nodeTypesFlag == "-textures") {
  975.         setupTextures $command $flag;
  976.  
  977.         tabLayout -e -tv true -tli 1 "Textures" indexTab;
  978.         tabLayout -e -st texturesTab -tv false creationWindowTabs;
  979.     }
  980.     else if ($nodeTypesFlag == "-shaders" || $nodeTypesFlag == "-shadersSG") {
  981.         setupShaders $command $flag;
  982.  
  983.         tabLayout -e -tv true -tli 1 "Materials" indexTab;
  984.         tabLayout -e -st shadersTab -tv false creationWindowTabs;
  985.         if($nodeTypesFlag == "-shaders") {
  986.             checkBox -e -v false shadingGroupCheckBox;
  987.         } else if($nodeTypesFlag == "-shadersSG") {
  988.             checkBox -e -v true shadingGroupCheckBox;
  989.         }
  990.     }
  991.     else if ($nodeTypesFlag == "-lights") {
  992.         setupLights $command $flag;
  993.  
  994.         tabLayout -e -tv true -tli 1 "Lights" indexTab;
  995.         tabLayout -e -st lightsTab -tv false creationWindowTabs;
  996.     }
  997.     else if ($nodeTypesFlag == "-utilities") {
  998.         setupUtilities $command $flag;
  999.  
  1000.         tabLayout -e -tv true -tli 1 "Utilities" indexTab;
  1001.         tabLayout -e -st utilitiesTab -tv false creationWindowTabs;
  1002.     }
  1003.     else
  1004.         error "Node type flag must be one of: -all,-allWithTexturesUp,-allWithShadersUp,-allWithLightsUp,-textures,-shadersSG,-shaders,-lights,-utilities";
  1005.  
  1006.     showWindow createRenderNodeWindow;
  1007.  
  1008.     // Establish a callback which will be called when a plugin is loaded.
  1009.     // The callback will find out what plugin was loaded and will update the
  1010.     // create render node window if necessary.
  1011.     //
  1012.     global int $gCreateRenderNodePluginCallbacksRegistered;
  1013.  
  1014.     if (!$gCreateRenderNodePluginCallbacksRegistered)
  1015.     {
  1016.         loadPlugin -addCallback createRenderNodeLoadPluginCallback;
  1017.         unloadPlugin -addCallback createRenderNodeUnloadPluginCallback;
  1018.         $gCreateRenderNodePluginCallbacksRegistered = true;
  1019.     }
  1020. }
  1021.  
  1022. proc createRenderNodePluginChange(
  1023.     string $changeType, 
  1024.     string $plugin)
  1025. {
  1026.     //
  1027.     // Description:
  1028.     //    This procedure is called from createRenderNodeLoadPluginCallback() or 
  1029.     //    from createRenderNodeUnloadPluginCallback(). If this method has been 
  1030.     //    called because a plugin has finished loading, $changeType should be
  1031.     //    "loadPlugin". If it has been called because a plugin is about to be
  1032.     //    unloaded, $changeType should be "unloadPlugin".
  1033.     //    This procedure determines what node types, if any, are affected by the
  1034.     //    plugin loading/unloading, and refreshes the createRenderNodeWindow if 
  1035.     //     any of those node types are displayed therein.
  1036.     //
  1037.  
  1038.     if (!`window -exists createRenderNodeWindow`)
  1039.     {
  1040.         return;
  1041.     }
  1042.  
  1043.     // Get a list of all node types loaded by the plugin
  1044.     //
  1045.     string $pluginNodeTypeArray[] = `pluginInfo -query -dependNode $plugin`;
  1046.  
  1047.     string $nodeType;
  1048.  
  1049.     for ($nodeType in $pluginNodeTypeArray)
  1050.     {
  1051.         // Determine the classification(s) of each node type. Note that nodes
  1052.         // can have multiple classifications.
  1053.         //
  1054.         string $classificationArray[] = `getClassification $nodeType`;
  1055.         string $classification;
  1056.  
  1057.         for ($classification in $classificationArray)
  1058.         {
  1059.             string $tokenArray[];
  1060.             tokenize($classification, "/", $tokenArray);
  1061.  
  1062.             if (    ($tokenArray[0] == "texture")
  1063.                 ||    ($tokenArray[0] == "shader")
  1064.                 ||    ($tokenArray[0] == "light")
  1065.                 ||    ($tokenArray[0] == "utility")
  1066.                 ||    ($tokenArray[0] == "imageplane")
  1067.                 ||    ($tokenArray[0] == "postprocess"))
  1068.             {
  1069.                 // The node type is classified as something which appears
  1070.                 // within the createRenderNodeWindow, so we need to refresh
  1071.                 // that window.
  1072.                 //
  1073.                 // Note that the above list needs to be kept in sync with the
  1074.                 // types of nodes which appear in the createRenderNodeWindow.
  1075.                 //
  1076.                 if ($changeType == "loadPlugin")
  1077.                 {
  1078.                     refreshCreateRenderNodeWindow($classification);
  1079.                 }
  1080.                 else if ($changeType == "unloadPlugin")
  1081.                 {
  1082.                     // The plugin is being unloaded, but is not yet gone. We
  1083.                     // want to refresh the createRenderNodeWindow but not until
  1084.                     // after the plugin has finished unloading. If we don't
  1085.                     // wait until the plugin has finished unloading, then the
  1086.                     // refreshed window will still contain the node types
  1087.                     // defined by the plugin.
  1088.                     // 
  1089.                     // To make sure the plugin has finished unloading before we
  1090.                     // refresh the window, we will defer the evaluation of the
  1091.                     // refresh command until idle time.
  1092.                     //
  1093.                     evalDeferred(
  1094.                         "refreshCreateRenderNodeWindow(\"" 
  1095.                         + $classification
  1096.                         + "\")");
  1097.                 }
  1098.             }
  1099.         }
  1100.     }
  1101. }
  1102.  
  1103. global proc createRenderNodeUnloadPluginCallback(string $plugin)
  1104. {
  1105.     //
  1106.     // Description:
  1107.     //    This procedure is called immediately before a plugin is unloaded.
  1108.     //    This procedure invokes createRenderNodePluginChange() to potentially
  1109.     //    refresh the createRenderNodeWindow.
  1110.     //
  1111.     createRenderNodePluginChange("unloadPlugin", $plugin);
  1112. }
  1113.  
  1114. global proc createRenderNodeLoadPluginCallback(string $plugin)
  1115. {
  1116.     //
  1117.     // Description:
  1118.     //    This procedure is called immediately after a plugin is loaded.
  1119.     //    This procedure invokes createRenderNodePluginChange() to potentially
  1120.     //    refresh the createRenderNodeWindow.
  1121.     //
  1122.     createRenderNodePluginChange("loadPlugin", $plugin);
  1123. }
  1124.  
  1125. global proc refreshCreateRenderNodeWindow( string $classification )
  1126. {
  1127.     if (!`window -exists createRenderNodeWindow`) {
  1128.         return;
  1129.     }
  1130.     
  1131.     // Description:
  1132.     //  If the mental ray plug-in is not loaded yet and the  
  1133.     //  Render Node window is already open without the mentalRayTab, 
  1134.     //  then after we load the mental ray plug-in, we want to update the
  1135.     //  Render Node Window to have one more tab -- the mentalRayTab. 
  1136.     //  This ensures that the mental ray tab gets 
  1137.     //  created if the mental ray plugin is loaded dynamically.
  1138.     //
  1139.     if (`window -query -visible createRenderNodeWindow` && !`columnLayout -exists mentalRayTab`) 
  1140.     {
  1141.         int $showMentalRayCustomShaders = 0;
  1142.         int $mentalRayPluginLoaded = 0;
  1143.  
  1144.         if (`getenv MAYA_MRFM_SHOW_CUSTOM_SHADERS` == "1")
  1145.         {
  1146.             $showMentalRayCustomShaders = 1;
  1147.         }
  1148.  
  1149.         if (`pluginInfo -query -loaded Mayatomr`)
  1150.         {
  1151.             $mentalRayPluginLoaded = 1;
  1152.         }
  1153.  
  1154.         if ($showMentalRayCustomShaders && $mentalRayPluginLoaded)
  1155.         {
  1156.             setParent creationWindowTabs;
  1157.             mrCreateNodeWindow_BuildTab;
  1158.             tabLayout -edit
  1159.                 -tl mentalRayTab "mental ray"
  1160.                 creationWindowTabs;
  1161.  
  1162.             setParent createRenderNodeWindow; 
  1163.             mrCreateNodeWindow_SetupTab "" "";
  1164.         }
  1165.     }
  1166.  
  1167.     // Turn on the wait cursor and unmanage the UI because it can take a few
  1168.     // moments to build the UI and the process can be ugly to watch
  1169.     //
  1170.     waitCursor -state on;
  1171.  
  1172.     formLayout
  1173.         -edit
  1174.         -manage false
  1175.         creationWindowForm;
  1176.  
  1177.     string $indiv[];
  1178.     tokenize($classification,":",$indiv);
  1179.  
  1180.     for( $class in $indiv ) {
  1181.         string $parent;
  1182.         string $RC;
  1183.         string $top;
  1184.     
  1185.         if( $class == "texture/2d" ) {
  1186.             $parent = "texturesTab|twoDTexturesF|twoDTexturesC";
  1187.             $RC = "twoDTexturesRC";
  1188.             $top = "texture";
  1189.         } else if( $class == "texture/3d" ) {
  1190.             $parent = "texturesTab|threeDTexturesF|threeDTexturesC";
  1191.             $RC = "threeDTexturesRC";
  1192.             $top = "texture";
  1193.         } else if( $class == "texture/environment" ) {
  1194.             $parent = "texturesTab|envTexturesF|envTexturesC";
  1195.             $RC = "envTexturesRC";
  1196.             $top = "texture";
  1197.         } else if( $class == "texture/other" ) {
  1198.             $parent = "texturesTab|otherTexturesF|otherTexturesC";
  1199.             $RC = "otherTexturesRC";
  1200.             $top = "texture";
  1201.         } else if( $class == "shader/surface" ) {
  1202.             $parent = "shadersTab|surfShadersF|surfShadersC";
  1203.             $RC = "surfShadersRC";
  1204.             $top = "shader";
  1205.         } else if( $class == "shader/volume" ) {
  1206.             $class = "shader/volume";
  1207.             $parent = "shadersTab|fogShadersF|fogShadersC";
  1208.             $RC = "fogShadersRC";
  1209.             $top = "shader";
  1210.         } else if( $class == "shader/displacement" ) {
  1211.             $class = "shader/displacement";
  1212.             $parent = "shadersTab|displacementShadersF|displacementShadersC";
  1213.             $RC = "displacementShadersRC";
  1214.             $top = "shader";
  1215.         } else if( $class == "light" ) {
  1216.             $parent = "lightsTab|lightsF|lightsC";
  1217.             $RC = "lightsRC";
  1218.             $top = "light";
  1219.         } else if( $class == "utility/general" ) {
  1220.             $parent = "utilitiesTab|generalUtilsF|generalUtilsC";
  1221.             $RC = "generalUtilsRC";
  1222.             $top = "utility";
  1223.         } else if( $class == "utility/switch" ) {
  1224.             $parent = "utilitiesTab|switchUtilsF|switchUtilsC";
  1225.             $RC = "switchUtilsRC";
  1226.             $top = "utility";
  1227.         } else if( $class == "utility/color" ) {
  1228.             $parent = "utilitiesTab|colorUtilsF|colorUtilsC";
  1229.             $RC = "colorUtilsRC";
  1230.             $top = "utility";
  1231.         } else if( $class == "utility/particle" ) {
  1232.             $parent = "utilitiesTab|partUtilsF|partUtilsC";
  1233.             $RC = "partUtilsRC";
  1234.             $top = "utility";
  1235.         } else if( $class == "imageplane" ) {
  1236.             $parent = "utilitiesTab|imgUtilsF|imgUtilsC";
  1237.             $RC = "imgUtilsRC";
  1238.             $top = "imageplane";
  1239.         } else if( $class == "postprocess/opticalFX" ) {
  1240.             $parent = "utilitiesTab|glowUtilsF|glowUtilsC";
  1241.             $RC = "glowUtilsRC";
  1242.             $top = "postprocess/opticalFX";
  1243.         } 
  1244.         else continue;
  1245.  
  1246.         string $parWndLayout;
  1247.         
  1248.         if(`about -mac`) {
  1249.             //    Fixes Bug #170869
  1250.             //    For Mac, we need add an extra layout, i.e Menubar layout.
  1251.             //
  1252.             $parWndLayout = "createRenderNodeWindow|createRenderNodeWindow|creationWindowForm|indexTab|creationWindowTabs|"+$parent;
  1253.         } else {
  1254.             $parWndLayout =  "createRenderNodeWindow|creationWindowForm|indexTab|creationWindowTabs|"+$parent;
  1255.         }
  1256.         $parentLayout = $parWndLayout;
  1257.  
  1258.         setParent $parentLayout;
  1259.         
  1260.         deleteUI $RC;
  1261.         refreshButtons($class,$RC);
  1262.         if(`about -mac`) {
  1263.             //    Fixes Bug #170869
  1264.             //    For Mac, we need add an extra layout, i.e Menubar layout.
  1265.             //
  1266.             setParent createRenderNodeWindow|createRenderNodeWindow|creationWindowForm|indexTab;
  1267.         } else {
  1268.             setParent createRenderNodeWindow|creationWindowForm|indexTab;
  1269.         }
  1270.  
  1271.         if( $top == "texture" ) {
  1272.             setupTextures "" "";
  1273.         } else if( $top == "shader" ) {
  1274.             setupShaders "" "";
  1275.         } else if( $top == "light" ) {
  1276.             setupLights "" "";
  1277.         } else if( $top == "utility" ) {
  1278.             setupUtilities "" "";
  1279.         }
  1280.     }
  1281.  
  1282.     // Now that we have finished building the UI, we can remanage the window
  1283.     // and turn off the wait cursor.
  1284.     //
  1285.     formLayout
  1286.         -edit
  1287.         -manage true
  1288.         creationWindowForm;
  1289.  
  1290.     waitCursor -state off;
  1291. }        
  1292.  
  1293.  
  1294.